﻿
Partial Class SearchKhachSan
    Inherits System.Web.UI.Page
    Public style_btn_next As String = ""
    Public active_next As String = ""
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        If Not IsPostBack Then
            If Request.QueryString("CityID") IsNot Nothing Then
                Dim idTinhThanh As New Guid(Request.QueryString("CityID"))
                Dim strCity As String = ""
                If Session("NameCity") IsNot Nothing AndAlso Not Session("NameCity").Equals("") Then
                    strCity = Session("NameCity")
                Else
                strCity = KhachSanServer.GetCityNameByIDCity(idTinhThanh)
                End If
                divNameCityTile.InnerHtml = strCity

                ''ArrivalDate=2014/2/10&DepartureDate=2014/2/11&CityID=ba8b21c6-3d8c-4116-8f46-9241fff0fd18&Guests=1&Rooms=1
                Session("IDCity") = Request.QueryString("CityID")
                Session("ArrivalDate") = Request.QueryString("ArrivalDate")
                Session("DepartureDate") = Request.QueryString("DepartureDate")
                Session("Guests") = Request.QueryString("Guests")
                Session("Rooms") = Request.QueryString("Rooms")
                Dim listKhachSan As List(Of KhachSan) = KhachSanServer.GetListKhachSanByIDTinhThanh(idTinhThanh, 0)
                Dim nCountAll As Integer = KhachSanServer.GetCountKhachSanByIDTinhThanh(idTinhThanh)
                LoadListKhachSan(listKhachSan, idTinhThanh, nCountAll)
                active_next = "onclick=""LoadContinuesListHotel(this)"""
            Else
                Response.Redirect("~/index.aspx")
            End If
        End If
        
    End Sub

    Private Sub LoadListKhachSan(ByVal listKhachSan As List(Of KhachSan), ByVal idCity As Guid, ByVal nCount As Integer)
        For i As Integer = 0 To listKhachSan.Count - 1
            Dim ks As KhachSan = listKhachSan(i)
            Dim urlImage As String = String.Format("http://www.khachsan24gio.vn{0}", ks.IMG_URL)
            Dim item As String = ""
            Dim urlDetail As String = String.Format("DetailKhachSan.aspx?IDKS={0}", ks.ID)
            item = String.Format("{0} <div style ='padding :10px;'> <div style ='float: left; padding-right: 10px;'> ", item)
            item = String.Format("{0} <a style ='text-decoration:none; width: 80px; height: 80px; display: block' href ='{1}' data-ajax='false'> ", item, urlDetail)
            item = String.Format("{0} <img width='80' height='80' alt='{1}' src='{2}' /> </a></div> ", item, ks.NAME, urlImage)
            item = String.Format("{0}  <div style =' color: #6B6B6B;font-size: 0.8em;'><div style ='color: #097AC8; font-size: 1.1em; font-weight: bold;'> ", item)
            'item = String.Format("{0}             <rewrites>  <add name= 'rewrite' virtualUrl= '^~/kien-thuc-seo/rewrite-url-asp-net.html' rewriteUrlParameter=  'ExcludeFromClientQueryString' destinationUrl= '~/product.aspx?cate_id=1&product_id=10' ignoreCase= 'true'/> </rewrites>")
            item = String.Format("{0} <a style='text-decoration:none;' href='{1}' data-ajax='false'> {2}</a> </div> ", item, urlDetail, ks.NAME)
            Dim strGia As String = ""
            If ks.HIENTHIGIA = True AndAlso ks.GIA > 0 Then
                strGia = Format(ks.GIA, "#,###")
            Else
                strGia = String.Format("<a class=""ui-link"" data-ajax='false' style=""text-decoration:none;"" href=""GetPrice.aspx?IDKS={0}"">Click lấy giá</a>", ks.ID)
            End If
            item = String.Format("{0} <div style ='color: #FFA500; float: right; font-size: 1.1em; font-weight: bold;'>{1}  </div>", item, strGia)
            Dim strStart As String = String.Format("Images/star-yellow-{0}-0.png", ks.STARS)

            item = String.Format("{0}  <div style =''><img  src='{1}'> </div> <div style =''> <img style='float: left;padding-right: 5px;' src='Images/hand.png' alt=''>", item, strStart)
            item = String.Format("{0} <div style ='padding-top: 2px;'>{1} đánh giá</div></div></div>", item, ks.COUNTDANHGIA)
            item = String.Format("{0} <div style ='clear :both ;'></div></div>", item)
            item = String.Format("{0} <div style ='background: none repeat scroll 0 0 #D1D1D1; height: 2px;'></div>", item)

            ''String.Format("<div style ='padding:10px;'><div id='{0}' style='cursor:pointer;' onclick='SelectedKhachSan(this)'>Khách sạn {1}</div></div>", listKhachSan(i).ID, listKhachSan(i).NAME)

            divListKhachSan.InnerHtml += item
        Next
        If nCount < listKhachSan.Count Or nCount = listKhachSan.Count Then
            style_btn_next = "style=""display:none"""
        End If
        divSoLuong.InnerHtml = String.Format("<span class=""num"">{0}</span> <span>khách sạn</span>", nCount)
        Dim dateFrom As Date = CDate(Request.QueryString("ArrivalDate"))
        Dim dateTo As Date = CDate(Request.QueryString("DepartureDate"))
        divSoPhongSoNguoi.InnerHtml = String.Format("Giá cho {0} người, {1} phòng ({2}/{3} - {4}/{5})", Request.QueryString("Guests"), Request.QueryString("Rooms"), dateFrom.Day, dateFrom.Month, dateTo.Day, dateTo.Month)
    End Sub

    Protected Sub lnkChapNhanSearch_Click(sender As Object, e As EventArgs) Handles lnkChapNhanSearch.Click
        Try
            txtSearchNameHotel.Text = ""
            LoadTheoDieuKien(0, "")
        Catch ex As Exception
            ''Throw ex
        End Try
    End Sub

    Protected Sub lnkSXTheoKhuyenMai_Click(sender As Object, e As EventArgs) Handles lnkSXTheoKhuyenMai.Click
        Try
            LoadTheoDieuKien(1, txtSearchNameHotel.Text)
        Catch ex As Exception
            ''Throw ex
        End Try
    End Sub

    Protected Sub lnkSXTheoGiaThap_Click(sender As Object, e As EventArgs) Handles lnkSXTheoGiaThap.Click
        Try
            LoadTheoDieuKien(2, txtSearchNameHotel.Text)
        Catch ex As Exception
            ''Throw ex
        End Try
    End Sub

    Protected Sub lnkSXTheoGiaCao_Click(sender As Object, e As EventArgs) Handles lnkSXTheoGiaCao.Click
        Try
            LoadTheoDieuKien(3, txtSearchNameHotel.Text)
        Catch ex As Exception
            ''Throw ex
        End Try
    End Sub

    Protected Sub lnkSXTheoAToZ_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkSXTheoAToZ.Click
        Try
            LoadTheoDieuKien(4, txtSearchNameHotel.Text)
        Catch ex As Exception
            ''Throw ex
        End Try
    End Sub

    Protected Sub lnkSXTheoZToA_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkSXTheoZToA.Click
        Try
            LoadTheoDieuKien(5, txtSearchNameHotel.Text)
        Catch ex As Exception
            ''Throw ex
        End Try
    End Sub

    Private Sub LoadTheoDieuKien(ByVal optionSX As Integer, ByVal nameSearch As String)
        Try
            Dim dangKM As Integer = 0
            If checkDangKM.Checked = True Then
                dangKM = 1
            Else
                dangKM = 0
            End If
            Dim arrStart As New ArrayList
            Dim arrGia As New ArrayList
            Dim json_start As String = "'["
            Dim json_price As String = "'["
            If checkStar_1.Checked = True Then
                json_start = json_start + "1,"
                arrStart.Add(1)
            Else
                json_start = json_start + "0,"
            End If
            If checkStar_2.Checked = True Then
                json_start = json_start + "1,"
                arrStart.Add(2)
            Else
                json_start = json_start + "0,"
            End If
            If checkStar_3.Checked = True Then
                json_start = json_start + "1,"
                arrStart.Add(3)
            Else
                json_start = json_start + "0,"
            End If
            If checkStar_4.Checked = True Then
                json_start = json_start + "1,"
                arrStart.Add(4)
            Else
                json_start = json_start + "0,"
            End If
            If checkStar_5.Checked = True Then
                json_start = json_start + "1"
                arrStart.Add(5)
            Else
                json_start = json_start + "0"
            End If
            json_start = json_start + "]'"
            If checkGia_0_5.Checked = True Then
                json_price = json_price + "1,"
                arrGia.Add("<500000 and 0<")
            Else
                json_price = json_price + "0,"
            End If
            If checkGia_5_10.Checked = True Then
                json_price = json_price + "1,"
                arrGia.Add("<=1000000 and 500000<=")
            Else
                json_price = json_price + "0,"
            End If
            If checkGia_10_20.Checked = True Then
                json_price = json_price + "1,"
                arrGia.Add("<=2000000 and 1000000<=")
            Else
                json_price = json_price + "0,"
            End If
            If checkGia_20_50.Checked = True Then
                json_price = json_price + "1,"
                arrGia.Add("<=5000000 and 2000000<=")
            Else
                json_price = json_price + "0,"
            End If
            If checkGia_50.Checked = True Then
                json_price = json_price + "1"
                arrGia.Add(">5000000 or 5000000=")
            Else
                json_price = json_price + "0"
            End If
            json_price = json_price + "]'"
            active_next = String.Format("onclick=""LoadContinuesListHotelAdd(this,{0},{1},{2},{3},'{4}')""", json_start, json_price, dangKM, optionSX, nameSearch)
            If Request.QueryString("CityID") IsNot Nothing Then
                Dim idTinhThanh As New Guid(Request.QueryString("CityID"))
                Dim listKhachSan As List(Of KhachSan) = KhachSanServer.SearchNangCaoListKhachSanByIDTinhThanh(idTinhThanh, dangKM, arrStart, arrGia, optionSX, 0, nameSearch)
                divListKhachSan.InnerHtml = ""
                Dim nCountAll As Integer = KhachSanServer.SearchNangCaoCountListKhachSanByIDTinhThanh(idTinhThanh, dangKM, arrStart, arrGia, optionSX, 0, nameSearch)
                LoadListKhachSan(listKhachSan, idTinhThanh, nCountAll)
            End If

        Catch ex As Exception
            ''Throw ex
        End Try
    End Sub

    Protected Sub lnkSearchNameHotel_Click(sender As Object, e As EventArgs) Handles lnkSearchNameHotel.Click
        Try
            Dim nameSearch As String = txtSearchNameHotel.Text
            LoadTheoDieuKien(4, nameSearch)
        Catch ex As Exception
            ''Throw ex
        End Try
    End Sub

    Protected Sub lnkSXTheoTieuChuan1To5_Click(sender As Object, e As EventArgs) Handles lnkSXTheoTieuChuan1To5.Click
        LoadTheoDieuKien(6, txtSearchNameHotel.Text)
    End Sub

    Protected Sub lnkSXTheoTieuChuan5To1_Click(sender As Object, e As EventArgs) Handles lnkSXTheoTieuChuan5To1.Click
        LoadTheoDieuKien(0, txtSearchNameHotel.Text)
    End Sub
End Class
